#10.3.2 使用try—expect代码块
try:
    print(5/0)
except ZeroDivisionError:
    print("You can't divide by zero !")
#注意：若try代码块运行正常，Python将跳过except代码块
#      若try代码块导致了错误，Python将运行except代码块


#10.3.3 使用异常避免崩溃
print("Give me two numbers , and I'll divide them")
print("Enter 'q' to quit.")

while True:
    first_number=input("\nFirst number:")
    if first_number=='q':
        break
    second_number=input('Second number:')
    if second_number=='q':
        break
    #使用异常处理
    try:
        answer=int(first_number)/int(second_number)
        print(answer)
    except ZeroDivisionError:
        print("Error input ! Please re-enter valid numbers !")


